import 'package:flutter_web/app/models/field_info.dart';

class InterfaceInfoModel {
  int? code;
  InterfaceInfoDataModel? data;
  String? message;

  InterfaceInfoModel({this.code, this.data, this.message});
  InterfaceInfoModel.fromJson(Map<String, dynamic> json) {
    code = json['code']?.toInt();
    data = (json['data'] != null)
        ? InterfaceInfoDataModel.fromJson(json['data'])
        : null;
    message = json['message']?.toString();
  }
  Map<String, dynamic> toJson() {
    final data = <String, dynamic>{};
    data['code'] = code;
    if (data != null) {
      data['data'] = this.data!.toJson();
    }
    data['message'] = message;
    return data;
  }
}

class InterfaceInfoDataModel {
  int? author;
  String? authorStr;
  List<InterfaceInfoDataBodyModel?>? body;
  List<InterfaceInfoDataHeaderModel?>? header;
  int? id;
  int? menuId;
  int? method;
  String? methodStr;
  String? name;
  String? path;
  List<InterfaceInfoDataQueryModel?>? query;
  List<InterfaceInfoDataJsonModel?>? json;

  InterfaceInfoDataModel({
    this.author,
    this.authorStr,
    this.body,
    this.header,
    this.id,
    this.menuId,
    this.method,
    this.methodStr,
    this.name,
    this.path,
    this.query,
  });
  InterfaceInfoDataModel.fromJson(Map<String, dynamic> json) {
    author = json['author']?.toInt();
    authorStr = json['author_str']?.toString();
    if (json['body'] != null) {
      
      body = <InterfaceInfoDataBodyModel>[];
      json['body'].forEach((v) {
        body?.add(InterfaceInfoDataBodyModel.fromJson(v));
      });
    }
    id = json['id']?.toInt();
    menuId = json['menu_id']?.toInt();
    method = json['method']?.toInt();
    methodStr = json['method_str']?.toString();
    name = json['name']?.toString();
    path = json['path']?.toString();
    if (json['query'] != null) {
      final v = json['query'];
      final arr0 = <InterfaceInfoDataQueryModel>[];
      v.forEach((v) {
        arr0.add(InterfaceInfoDataQueryModel.fromJson(v));
      });
      query = arr0;
    }
  }
  Map<String, dynamic> toJson() {
    final data = <String, dynamic>{};
    data['author'] = author;
    if (body != null) {
      final v = body;
      final arr0 = [];
      v!.forEach((v) {
        arr0.add(v!.toJson());
      });
      data['body'] = arr0;
    }
    data['id'] = id;
    data['menu_id'] = menuId;
    data['method'] = method;
    data['method_str'] = methodStr;
    data['name'] = name;
    data['path'] = path;
    if (query != null) {
      final v = query;
      final arr0 = [];
      v!.forEach((v) {
        arr0.add(v!.toJson());
      });
      data['query'] = arr0;
    }
    return data;
  }
}

class InterfaceInfoDataQueryModel {

  String? exampleValue;
  String? fieldName;
  String? isRequired;
  String? remark;

  InterfaceInfoDataQueryModel({
    this.exampleValue,
    this.fieldName,
    this.isRequired,
    this.remark,
  });
  InterfaceInfoDataQueryModel.fromJson(Map<String, dynamic> json) {
    exampleValue = json['exampleValue']?.toString();
    fieldName = json['fieldName']?.toString();
    isRequired = json['isRequired']?.toString();
    remark = json['remark']?.toString();
  }
  Map<String, dynamic> toJson() {
    final data = <String, dynamic>{};
    data['exampleValue'] = exampleValue;
    data['fieldName'] = fieldName;
    data['isRequired'] = isRequired;
    data['remark'] = remark;
    return data;
  }
}

class InterfaceInfoDataBodyModel {

  String? exampleValue;
  String? fieldName;
  String? isRequired;
  String? remark;
  String? type;

  InterfaceInfoDataBodyModel({
    this.exampleValue,
    this.fieldName,
    this.isRequired,
    this.remark,
    this.type,
  });
  InterfaceInfoDataBodyModel.fromJson(Map<String, dynamic> json) {
    exampleValue = json['exampleValue']?.toString();
    fieldName = json['fieldName']?.toString();
    isRequired = json['isRequired']?.toString();
    remark = json['remark']?.toString();
    type = json['type']?.toString();
  }
  Map<String, dynamic> toJson() {
    final data = <String, dynamic>{};
    data['exampleValue'] = exampleValue;
    data['fieldName'] = fieldName;
    data['isRequired'] = isRequired;
    data['remark'] = remark;
    data['type'] = type;
    return data;
  }
}


class InterfaceInfoDataHeaderModel {

  String? fieldName;
  String? value;
  String? remark;

  InterfaceInfoDataHeaderModel({
    this.fieldName,
    this.value,
    this.remark,
  });
  InterfaceInfoDataHeaderModel.fromJson(Map<String, dynamic> json) {
    fieldName = json['fieldName']?.toString();
    value = json['value']?.toString();
    remark = json['remark']?.toString();
  }
  Map<String, dynamic> toJson() {
    final data = <String, dynamic>{};
    data['fieldName'] = fieldName;
    data['value'] = value;
    data['remark'] = remark;
    return data;
  }
}


class InterfaceInfoDataJsonModel {

  String? name;
  String? value;
  String? desc;
  String? type;
  String? isRequired;

  List<InterfaceInfoDataJsonModel>? children;

  InterfaceInfoDataJsonModel({
    this.name,
    this.value,
    this.desc,
    this.type,
    this.isRequired,
    this.children,
  });
  InterfaceInfoDataJsonModel.fromJson(Map<String, dynamic> json) {
    name = json['name']?.toString();
    value = json['value']?.toString();
    desc = json['desc']?.toString();
    type = json['type']?.toString();
    isRequired = json['isRequired']?.toString();

    if (json['children'] != null) {
      
      children = <InterfaceInfoDataJsonModel>[];
      json['children'].forEach((v) {
        children?.add(InterfaceInfoDataJsonModel.fromJson(v));
      });
    }
  }
  Map<String, dynamic> toJson() {
    final data = <String, dynamic>{};
    data['name'] = name;
    data['value'] = value;
    data['desc'] = desc;
    data['type'] = type;
    return data;
  }
}
// 扁平化节点模型（用于渲染）
class FlatJsonItem {
  InterfaceInfoDataJsonModel item;
  int level;
  bool isExpanded;

  FlatJsonItem({
    required this.item,
    this.level = 0,
    this.isExpanded = true,
  });
}